<?php
header("Content-Type:json/html;charset=utf8");

$config = require '../config.php';

$username  = $_POST['username'];
$password  = $_POST['password'];
$email  = $_POST['email'];
$address  = $_POST['address'];



$conn = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);
$sql = "select * from users where '$username' = username";

if(($conn->query($sql))->num_rows == 0){
    $sql = "insert into users( username, password, email, address) values ('$username','$password','$email','$address')";
    $result = $conn->query($sql);
    if($result){
        $result = ['code' =>1,'msg' => "注册成功!"];
    }else{
        $result = ['code' =>-1,'msg' => "未知错误,请重试!"];
    }
}else{
    //     已有相同用户名 请重新输入用户名
    $result = ['code' =>0,'msg' => "注册失败,已存在相同用户名"];
}
echo json_encode($result) ;
$conn->close();